package com.designpattern.structure.enjoy;

import java.util.HashMap;

/**
 * @author Administration
 * @date 2021/10/19 - 14:54 - 星期二
 * @project lambda
 * @package com.designpattern.structure.enjoy
 * @by 晨
 */
public class BoxFactory {

    private HashMap<String, AbstractBox> map;

    public BoxFactory() {
        System.out.println("加载无参构造方法");
        map = new HashMap<>();
        AbstractBox iBox = new IBox();
        AbstractBox lBox = new LBox();
        AbstractBox oBox = new OBox();
        map.put("I",iBox);
        map.put("L",lBox);
        map.put("O",oBox);
    }

    // 饿汉式加载实例化对象
    private static BoxFactory boxFactory;

    static {
        boxFactory = new BoxFactory();
    }

    public static BoxFactory SingletonHolder (){
        return boxFactory;
    }

    public AbstractBox getBox(String key) {
        AbstractBox abstractBox = map.get(key);
        return abstractBox;
    }
}
